﻿using System;
using System.Collections.Generic;

using System.Windows.Forms;

namespace ExcleToWord.DataModel
{
    public class RecordFilterUtil
    {

        //         private KeyValuePair<string, string> _productIdPair;  //商品ID
        //         private KeyValuePair<string, string> _namePair;  //商品名称
        //         private KeyValuePair<string, string> _pricePair; //价格
        //         private KeyValuePair<string, string> _platformPair;  //平台
        //         private KeyValuePair<string, string> _couponInfoPair;  //优惠券信息
        //         private KeyValuePair<string, string> _discountPricePair;  //折后价格
        //         private KeyValuePair<string, string> _orderLongLinkPair;  //全链接

        public static void ProcessFilter(List<RecordEntity> sheetData, List<string> outItemNamesList,
            out List<Dictionary<string, string>> filteredSheetList)
        {
            //0. 预处理
            filteredSheetList = null;
            if (sheetData == null || sheetData.Count == 0 || outItemNamesList == null)
            {
                MessageBox.Show("Error", "ProcessFilter()");
                return;
            }

            //2.遍历每一行,如果filteredRecordDictionary中有需要名字就处理
            filteredSheetList = new List<Dictionary<string, string>>();

            //3.1遍历所有行
            for (int i = 0; i < sheetData.Count; i++)
            {

                List<KeyValuePair<string, string>> pariList = sheetData[i].RecordList; //每一行的数据

                Dictionary<string, string> recordDic = new Dictionary<string, string>();

                //2.2 遍历所有列
                for (int j = 0; j < pariList.Count; j++)
                {
                    KeyValuePair<string, string> itemFond = pariList[j];
                    for (int k = 0; k < outItemNamesList.Count; k++)
                    {
                        string strName = outItemNamesList[k];
                        if (strName == itemFond.Key)
                        {
                            if (!recordDic.ContainsKey(itemFond.Key))
                            {
                                recordDic.Add(itemFond.Key, itemFond.Value);
                                // Question ???  直接添加？   [2016-11-19  05:31 pm By:ZhangChengbo]
                            }
                        }
                    }
                    //KeyValuePair<string, string> itemFond = pariList.Find(
                    //    p => outItemNamesList.Contains(p.Key.Trim()));
                }
                filteredSheetList.Add(recordDic);
            }
        }
    }
}
